<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 精度丢失
        console.log(0.2 + 0.1);//0.30000000000000004

        // 1.其它类型----Number
        // String---Number     ''   '   '     '123hello'   'hello123'   '123'
        var str = '';
        str = Number(str);
        console.log(str, typeof str);//0 'number'

        var str1 = ' ';
        str1 = Number(str1);
        console.log(str1, typeof str1);//0 'number'


        var str2 = '123hello';
        str2 = Number(str2);
        console.log(str2, typeof str2);//NaN 'number'

        var str3 = 'he123llo123';
        str3 = Number(str3);
        console.log(str3, typeof str3);//NaN 'number'

        console.log(Number('123')); //123  

        console.log(parseInt('123'), parseInt('123.456')); //123 123
        console.log(parseInt('123hello'), parseInt('123.456hello')); //123 123

        console.log(parseInt('hello123'), parseInt('hello'), parseInt(''), parseInt('   '));//NaN NaN NaN NaN

        console.log(parseFloat('123hello'), parseFloat('123.456hello')); //123 123.456


        // Boolean---Number      true  false
        console.log(Number(true));//1
        console.log(Number(false));//0
        console.log(parseInt(true), parseInt(false));//NaN

        //   Undefined   Null--- Number
        var a;
        console.log(Number(a), parseInt(a), parseFloat(undefined));//NaN NaN NaN


        var b = null;
        console.log(Number(b), parseInt(b), parseFloat(null));//0 NaN NaN

        // 隐式
        var c = '123';
        console.log(c, typeof c);//123 string
        c = +c;
        console.log(c, typeof c);//123 'number'
    </script>
</body>

</html>